﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using OhioState.Graphics;
using OhioState.Controls;
using OhioState.Graphics.Proxy;
using OhioState.Graphics.OpenGL;
using OhioState.AssetManaged;
using System.Configuration;
using OhioState.Math;

namespace GL_Panel
{
    /// <summary>
    /// This is an example of creating simple remote camera control.
    /// This control can be run on a machine without OpenGL support,
    /// such as a some sort of a handheld device.
    /// </summary>
    public partial class SimpleForm : Form
    {
        private static String address = "tcp://localhost:8007/";
        private ExaminerMouseHandler examiner;
        private ICamera camera;
        private ConnectForm connectForm;

        public SimpleForm()
        {
            connectForm = new ConnectForm();
            connectForm.connectEvent += new ConnectForm.Connecting(connectForm_connectEvent);

            InitializeComponent();
            connectForm.Show(this);
            this.Text = "Remote Camera Control";
        }

        void connectForm_connectEvent(object sender, EventArgs e)
        {
            address = "tcp://" + connectForm.GetText() + ":8007/";
            InitializeRemoteCamera();
        }

        private void InitializeRemoteCamera()
        {
            AppSettingsReader appSettingReader = new AppSettingsReader();
            try
            {
                AssetManager assetManager = (AssetManager)Activator.GetObject(typeof(AssetManager), address + "Asset Manager");
                camera = (ICamera)assetManager.Find(typeof(ICamera), "PerspectiveView");
            }
            catch
            {
                DialogResult dr = MessageBox.Show("Could not connect to remote machine. Closing.",
                    "Error", MessageBoxButtons.OK);
                if (dr == DialogResult.OK)
                {
                    Application.Exit();
                }
            }

            examiner = new ExaminerMouseHandler();
            examiner.OwnerControl = renderPanel;
            examiner.AddSlave(camera as ITransform);
            examiner.AddSlave(camera as IZoomLens);
        }
    }
}
